Skip to content

Conversation

nickkuk
Copy link
Contributor

@nickkuk nickkuk commented Sep 8, 2025

New tokio_util::task::JoinQueue structure as FIFO-ordered analog of tokio::task::JoinSet.

Issue: #7576

Edit: renamed from JoinDeque to JoinQueue.

@ADD-SP ADD-SP added C-enhancement Category: A PR with an enhancement or bugfix. A-tokio-util Area: The tokio-util crate M-task Module: tokio/task labels Sep 9, 2025
Copy link
Member

@ADD-SP ADD-SP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should replicate most of the methods from JoinSet.

@ADD-SP ADD-SP added the S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. label Sep 10, 2025
@nickkuk nickkuk force-pushed the join_deque branch 2 times, most recently from 2c34aef to 837875d Compare September 10, 2025 19:50
@nickkuk
Copy link
Contributor Author

nickkuk commented Sep 10, 2025

I think we should replicate most of the methods from JoinSet.

Ok, I pushed implementation of all methods except try_join_next and try_join_next_with_id. Do you know how to implement them?

@nickkuk nickkuk requested a review from ADD-SP September 10, 2025 20:04
Copy link
Member

@ADD-SP ADD-SP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is not the double-ended queue, I would suggest change it to another name.

@nickkuk nickkuk changed the title util: add JoinDeque structure util: add JoinQueue data structure Sep 11, 2025
///
/// [`join_next`]: fn@Self::join_next
/// [`JoinError::id`]: fn@tokio::task::JoinError::id
pub async fn join_all(mut self) -> Vec<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All async functions must have a cancel safety section in the documentation.

Comment on lines +270 to +273
// A JoinHandle generally won't emit a wakeup without being ready unless
// the coop limit has been reached. We yield to the executor in this
// case.
cx.waker().wake_by_ref();
Copy link
Contributor

@Darksonn Darksonn Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong because self.0.front_mut() is not the same as the pop_notified() used by JoinSet. Since you always poll a JoinHandle no matter what, you should not call wake_by_ref() here. This will cause needless spinning.

Please add a test that would have caught this bug. You can look at tests using tokio_test::spawn for examples of how you can detect whether wakeups are sent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-util Area: The tokio-util crate C-enhancement Category: A PR with an enhancement or bugfix. M-task Module: tokio/task S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants